//
//  LWH_ViewForEveryDaySectionHeader.m
//  ProjectB_
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 项目B. All rights reserved.
//

#import "LWH_ViewForEveryDaySectionHeader.h"
#import "LWH_EveryDayModelForSection.h"
@interface LWH_ViewForEveryDaySectionHeader ()
@property (nonatomic, strong) UILabel *labelForTitle;   //区头的title 随机出现
@property (nonatomic, strong) UIImageView *imageViewForHeader;  //区头的照片 随机出现
@end

@implementation LWH_ViewForEveryDaySectionHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.labelForTitle = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelForTitle];
        self.labelForTitle.textAlignment = 1;
        
        
        self.imageViewForHeader = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageViewForHeader];
    }
    return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (self.labelForTitle.text) {
        self.labelForTitle.frame = self.bounds;
        self.labelForTitle.center = CGPointMake(self.bounds.size.width / 2.f, self.bounds.size.height / 2.f);
    } else {
        self.imageViewForHeader.frame = CGRectMake(self.bounds.size.width / 4, self.bounds.size.height / 3, self.bounds.size.width / 2, self.bounds.size.height / 3);
    }
    
}
- (void)passData:(LWH_EveryDayModelForSection *)model {
    
    if ([model.type isEqualToString:@"textHeader"]) {
        self.labelForTitle.text = model.text;
    } else {
        [self.imageViewForHeader sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil];
    }
}
@end
